package com.soft.service.impl;

import com.soft.dao.SalesMapper;
import com.soft.model.BusinessExample;
import com.soft.model.Sales;
import com.soft.model.SalesExample;
import com.soft.service.SalesService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("salesService")
public class SalesServiceImpl implements SalesService {

    @Autowired
    private SalesMapper mapper;

    @Override
    public Sales getById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Sales getByUserName(String username) {

        SalesExample example = new SalesExample();
        SalesExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Sales> users = mapper.selectByExample(example);
        System.out.println(users);
        if (users != null && users.size() > 0) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public List<Sales> getAll(Integer businessId) {


        return mapper.selectByBusinessId(businessId);
    }

    @Override
    public List<Sales> getAll() {

        return mapper.selectByExample(null);
    }

    @Override
    public int add(Sales user) {
        return mapper.insertSelective(user);
    }

    @Override
    public int update(Sales user) {
        return mapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int delete(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

}
